<template>
	<view class="scan">
		<view class="uni-padding-wrap uni-common-mt">
			<view class="tip">扫码成功，请确认登录</view>
			<button type="primary" :disabled="isDisabled" @click="confirm">确 认</button>
		</view>
	</view>
</template>

<script>
	export default {
		props: ['accessToken', 'prevPage', 'getUserMsg'],
		data (){
			 return {
				 isDisabled: false
			 }
		},
		methods: {
			async confirm (){
				this.isDisabled = true
				let result = await this.$request.post('/accesstoken', {
					accesstoken: this.accessToken
				})
				if(result.success){
					uni.showToast({
						title: '登录成功',
						duration: 2000
					})
					uni.setStorage({
						key: 'access_token', 
						data: this.accessToken
					})
					this.$store.commit('add_access_token', {
						token: this.accessToken
					})
					this.getUserMsg(result['loginname'])
				}else{
					return 'false'
				}
				this.isDisabled = false
			}
		}
	}
</script>

<style lang="scss">
	.scan{
		position: absolute;
		z-index: 100;
		left: 0;
		right: 0;
		bottom: 0;
		top: 0;
		background-color: #FFFFFF;
		.tip{
			padding: 50px 0 30px;
			text-align: center;
			font-size: 16px;
			color: #666;
		}
		button,
		uni-button{
			width: 80%;
			border-radius: 0;
			&::after{
				border-radius: 0;
			}
		}
	}
</style>
